package oldVersion.server;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.Socket;

public class Playlist {
	public Playlist(){

	}

	public String getNextSong(){
		return "<location>rtp://137.43.200.113:5000/audio</location><title>tuner1.wav</title>";
	}
	
	
	
	public void talkToStorage(String song){
		
		//we just need to tell storage which song will be streamed 
		// Data sink address is set to specific (ie rtp://137.43.200.113:5000/audio) which will be used by all storage devices to stream to
		
		String add = getNextSong();
		//String ipPort[] = add.split(":");// i don't know the format of the string so ...just mentioning
		String ip = "137.43.200.214"; //ipPort[0];
		int port = 5000;//Integer.parseInt(ipPort[1]);
				
		try {

			Socket s = new Socket (ip,port);
			
			OutputStream os = s.getOutputStream();
			PrintWriter pw = new PrintWriter(os,true);
	
									//storage will be told to stream this song
			
			pw.println(song);
	
			s.close();
		}
		catch (Exception ex) {
			System.out.println(ex);
		}
		
		
		
		
	}
	
	public void talkToHifi(){
		
		//suppose we know what the ip and the port is of HiFi then simply
		// This is from where we can control HiFi as well.
		
		String ip="137....";
		int port = 500;
		String msg = null;
		try {

			Socket s = new Socket (ip,port);
			InputStream is = s.getInputStream();
			InputStreamReader isr = new InputStreamReader(is);
			BufferedReader br = new BufferedReader(isr);
			String whtHifiDoing = br.readLine();
			
			
			OutputStream os = s.getOutputStream();
			PrintWriter pw = new PrintWriter(os,true);
			
			if (whtHifiDoing.equals("nothing")){	
	
			msg ="play"; 		//this is wht will be said Hifi to do 
								// since Hifi already knows the data sink address so it will start getting the streamd.
			}
			else {
				
				msg = "stop";		// the Hifi will be said to stop the music currently playing or something else.
				
			}
			
			pw.println(msg);
	
			s.close();
		}
		catch (Exception ex) {
			System.out.println(ex);
		}
		
		
	}
}
